/*
 * GameBoard.h
 *
 *  Created on: 13.12.2010
 *      Author: v.v.baklanov
 */

#ifndef GAMEBOARD_H_
#define GAMEBOARD_H_

#include <QtGlobal>
#include <QtCore/QPair>
#include <QtCore/QVector>
#include <QtCore/QHash>
#include <QDebug>

class GameBoard {
public:
	enum dir {
		N = -8, NE = -7, E = 1, SE = 9, S = 8, SW = 7, W = -1, NW = -9
	};//magic numbers? )) binary mask offset for certain direction in 8x8 square
	GameBoard();
	virtual ~GameBoard();

	void init();
	bool placeBid(int row, int column, bool playerId);
	int getCell(int row, int column) const;
	int rowCount() const;
	int columnCount() const;

	void checkCell(int row, int column);
	QVector<QPair<int, int> > possibleMoves(bool playerId);

private:
	int rows, columns;
	quint64 marks[2];
	QHash<GameBoard::dir, quint64> dirFlags;
	QVector<GameBoard::dir> dirs;

	quint64 indexToMask(int row, int column) const;
	QPair<int, int> maskToIndex(quint64 mask) const;

	void reverseLine(quint64 startMask, quint64 endMask);
	void reverseBid(int row, int column);
	quint64 checkLine(quint64 mask, bool playerId, GameBoard::dir direction);
	QVector<quint64> checkAllLines(quint64 number, bool playerId);
	quint64 getNextCell(quint64 currentCell, GameBoard::dir direction);
};

#endif /* GAMEBOARD_H_ */
